package com.aegis.common.web;


import com.aegis.common.exception.BaseException;

public class ResultUtil {

    /**
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genSuccessResult() {
        return WebResponse.<T>newInstances()
                .setByResponseEnum(BaseResponseEnum.SUCCESS);
    }


    /**
     * @param data
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genSuccessResult(T data) {
        return WebResponse.<T>newInstances()
                .setByResponseEnum(BaseResponseEnum.SUCCESS)
                .setData(data);
    }

    /**
     * @param message
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genFailResult(String message) {
        return WebResponse.<T>newInstances()
                .setCode(BaseResponseEnum.BAD_REQUEST.getCode())
                .setMessage(message);
    }


    /**
     * @param responseEnum
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genFailResult(IResponseEnum responseEnum) {
        return WebResponse.<T>newInstances()
                .setByResponseEnum(responseEnum);
    }


    /**
     * @param responseEnum
     * @param message
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genFailResult(IResponseEnum responseEnum, String message) {
        return WebResponse.<T>newInstances()
                .setCode(responseEnum.getCode())
                .setMessage(message);
    }

    /**
     * @param exception
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genExceptionResult(BaseException exception) {
        return WebResponse.<T>newInstances()
                .setMessage(exception.getMessage())
                .setCode(exception.getCode());
    }

    /**
     * 系统级别错误信息
     *
     * @param sysMessage
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genSysFailResult(String sysMessage) {
        return WebResponse.<T>newInstances()
                .setByResponseEnum(BaseResponseEnum.BAD_REQUEST)
                .setSysMessage(sysMessage);
    }

    /**
     * @param code
     * @param message
     * @param <T>
     * @return
     */
    public static <T> WebResponse<T> genCommonResult(Integer code, String message) {
        return WebResponse.<T>newInstances()
                .setCode(code)
                .setMessage(message);
    }

}
